const http = require('http')
const port = 3000

const server = http.createServer()
server.on('request', (request, response) => {

  // 修改响应状态码
  response.statusCode = 404
  // 指定响应头 告知浏览器响应的内容的类型
  // end方法，它只能返回字符串
  // response.setHeader('Content-Type', 'text/plain;charset=utf-8')
  // response.end('你好nodejs')
  response.setHeader('Content-Type', 'text/html;charset=utf-8')
  response.end('<h3>你好nodejs</h3>')
  /* response.setHeader('Content-Type', 'application/json;charset=utf-8')
  response.end(JSON.stringify({
    code: 0,
    msg: 'ok',
    data: [{ id: 1, name: '张三' }]
  })) */
})

server.listen(3000, '0.0.0.0', () => {
  console.log('http://localhost:3000')
})


